import 'dart:convert';

import 'package:http/http.dart' as http;
import 'package:netstorage/model/search_model.dart';
import 'package:netstorage/utils/navigator_utils.dart';

class SearchDao {
  static Future<SearchModel?> fetch() async {
    String uri = 'https://xdfznh.club/zknoteb/flutter/searchData';
    var url = Uri.parse(uri);
    final res = await http.post(url);
    Utf8Decoder utf8decoder = const Utf8Decoder();
    String bodyStr = utf8decoder.convert(res.bodyBytes);
    if(res.statusCode == 200){
      var map = jsonDecode(bodyStr);
      return SearchModel.fromJson(map);
    }
    if(res.statusCode == 401){
      NavigatorUtils.goLogin();
      return null;
    }
    throw Exception(bodyStr);
  }
}